package cycling.taxi.com.ui.activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cycling.taxi.com.R;
import cycling.taxi.com.bean.LocationInfo;
import cycling.taxi.com.bean.UserVerhicle;
import cycling.taxi.com.person.ExitApplication;
import cycling.taxi.com.utils.PowerUtils;
import cycling.taxi.com.utils.SPUtil;

/**
 * Created by Administrator on 2017/5/3.
 */
public class LowBatteryAty extends AppCompatActivity implements View.OnClickListener {
    @InjectView(R.id.battery_tv)
    TextView batteryTv;
    @InjectView(R.id.legend_tv)
    TextView legendTv;
    @InjectView(R.id.current_tv)
    TextView currentTv;
    @InjectView(R.id.voltage_tv)
    TextView voltageTv;
    @InjectView(R.id.standby_voltage_tv)
    TextView standbyVoltageTv;

    private ImageView back;
    private LocationInfo mElectricityInfo;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_lowbattery);
        ExitApplication.getInstance().addActivity(this);

        initView();

        initData();

        setListener();

    }

    private void initData() {
        mElectricityInfo = (LocationInfo) SPUtil.getInstance().getBean("electricityInfo", LocationInfo.class);

        legendTv.setText(mElectricityInfo.getMileage());
        currentTv.setText(mElectricityInfo.getElectric_current());
        voltageTv.setText(mElectricityInfo.getVol());
        standbyVoltageTv.setText(mElectricityInfo.getStandby_voltage());
        PowerUtils powerUtils=new PowerUtils();
        String verhicledata =SPUtil.getInstance().getData("verhicledata");
        Gson gson = new Gson();
        UserVerhicle userVerhicle= gson.fromJson(verhicledata, UserVerhicle.class);
        batteryTv.setText(powerUtils.Power(userVerhicle.getVehicleMotorpower(),mElectricityInfo.getVol()));
    }

    private void setListener() {
        back.setOnClickListener(this);
    }

    private void initView() {
        back = (ImageView) findViewById(R.id.back);
        ButterKnife.inject(this);

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.back) {
            finish();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
